<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>申报参数设置</title>
		<%@ include file="/WEB-INF/jsp/include.jsp"%>
		<style type="text/css">

		</style>
		<script type="text/javascript">
		var path = "${path}";
		var queryParams=new Object();
		
		var params = new Object();
		
		var url=path+"/tdm/declareParameter/queryByPage";
		
		var layer_index_sjdy;
		var layer_jqobj_sjdy;
		$(function(){
			setAjaxLoading();
			
			$("#taxPayerId").combobox({
				editable: false,
				valueField: "code",
				textField: "name",
				onSelect: function (record) {
					var value = record.code;
//					loadSzxxByNszt(value);
				}
			});
			
			$("#taxCode").combobox({
				editable: false,
				valueField: "code",
				textField: "name"
			});
			
//			
			var grid=$("#tt");
			initGrid(grid);
		});
		
 
		//初始化表格和数据
		function initGrid(grid) {
		    var columns=[
                		{ field: "cbid", title: "cbid", align: "left",hidden:"true",halign: "center", sortable: false, resizable: true, width: 250},
                		{ field: "cpid", title: "cpid", align: "left",hidden:"true",halign: "center", sortable: false, resizable: true, width: 250},
			            { field: "taxPayerName", title: "纳税主体", align: "left",halign: "center", sortable: false, resizable: true, width: 300},
			            { field: "taxCode", title: "税（费）种", align: "center",halign: "center", sortable: false, resizable: true, width: 150},
						{ field: "tdperdCode", title: "纳税申报", align: "center",halign: "center", sortable: false, resizable: true, width: 150},
						{ field: "taxperd", title: "所属属期", align: "center",halign: "center", sortable: false, resizable: true, width: 120},
			            { field: "taxperdFrom", title: "所属期起", align: "center",halign: "center", sortable: false, resizable: true, width: 120,
                            formatter : function(value){
                                var date = new Date(value);
                                var y = date.getFullYear();
                                var m = date.getMonth() + 1;
                                var d = date.getDate();
                                if(m<10){
                                    m="0"+m;
                                }
                                if(d<10){
                                    d="0"+d;
								}
                                return y + '-' +m + '-' + d;
                            }},
			            { field: "taxperdTo", title: "所属期止", align: "center",halign: "center", sortable: false, resizable: true, width: 120,
                            formatter : function(value){
                                var date = new Date(value);
                                var y = date.getFullYear();
                                var m = date.getMonth() + 1;
                                var d = date.getDate();
                                if(m<10){
                                    m="0"+m;
                                }
                                if(d<10){
                                    d="0"+d;
                                }
                                return y + '-' +m + '-' + d;
                            }}
			        ];

		    initPageGrid(grid, queryParams, url,columns,"#tb");
		    getPage(grid,queryParams,url);
		    
		    var grid_options = $("#tt").datagrid("options");
		    grid_options.onDblClickRow = function(rowIndex, rowData) {
		    	btnEdit();
		    }
		}
		
		//查询
		function btnQuery() {
			var param = new Object();
			
			var taxPayerId = $("#taxPayerId").combobox("getValue");
			if (taxPayerId != null && taxPayerId != "" && taxPayerId != "null" && taxPayerId != "-1") {
				param.taxPayerId = taxPayerId;
			}
			
			var taxCode = $("#taxCode").combobox("getValue");
			if (taxCode != null && taxCode != "" && taxCode != "null" && taxCode != "-1") {
				param.taxCode =	taxCode;
			}
			
			var taxperdFrom = $("#taxperdFrom").datebox("getValue");
			var taxperdTo = $("#taxperdTo").datebox("getValue");

            var  taxperdFromDate = "";
            var  taxperdToDate = "";
            
            if(taxperdFrom != "" ){
                var array =  taxperdFrom.split("-");
                taxperdFromDate = new Date(array[0], array[1]-1, array[2]);
                queryParams.taxperdFrom = taxperdFromDate;
			}else{
                taxperdFromDate = new Date(2000,0,1);
			}
			if(taxperdTo != ""){
                var array2 =  taxperdTo.split("-");
                taxperdToDate = new Date(array2[0], array2[1]-1, array2[2]);
                queryParams.taxperdTo = taxperdToDate;
			}else{
                taxperdToDate =  new Date(2118,0,1);
			}
			
			queryParams.taxCode = taxCode;
			queryParams.orgCode = taxPayerId;

//			$.extend(queryParams, param);
			queryParams.pageNumber = 1; 
			var grid=$("#tt");
    		getPage(grid,queryParams,url);
		}
		
		function refreshGrid() {
			var grid=$("#tt");
			refresh(grid,url);
		}
		
		
		//批量增加
		function btnBatchAdd() {
			top.layer.open({
			  type: 2,
			  title: '添加',
			  shadeClose: false, 
				shade: [0.8, '#393D49'],//遮罩层 
//				maxmin: true,
//                closeBtn:0, 
				area: ['800px', '600px'],
			  content: '${path}/tdm/declareParameter/toAdd',
			  success: function(layero, index){
				  	
			  },
			  end: function () {
                  btnQuery();		  
			  }
			  ,
                cancel: function(index,layero){
                    $(layero).find("iframe")[0].contentWindow.closeBtn();
//                    //关闭layer弹窗
//					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//					parent.layer.close(index); //再执行关闭
                    
                }
			}); 
		}

        //修改
		function btnEdit() {
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        $.messager.alert("信息", "请先选择一个项目！", "info");
		        return;
		    }
		    
		    var row = rows[0];
    		var param = new Object();
    		var cbid = row.cbid;
            var cpid = row.cpid;
            var url = '${path}/tdm/declareParameter/toUpdate?cbid='+cbid+"&cpid="+cpid;
            top.layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                shade: [0.8, '#393D49'],//遮罩层 
//				maxmin: true,
//                closeBtn:0,
                area: ['800px', '600px'],
                content: url,
                success: function(layero, index){

                },
                end: function () {
                    btnQuery();
                }
            });
  
		}
		//删除
		function btnDel(){
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        $.messager.alert("信息", "请先选择一个项目！", "info");
		        return;
		    }
		    
			var rowData = rows[0];
			
			var param = new Object();
			param.cpid = rowData.cpid;
            param.cbid = rowData.cbid;
			$.messager.alert("信息", "该删除后将不可恢复，是否删除？","confirm", function () {

	    			$.ajax({
		        		type:"POST",
		       			url:path+'/tdm/declareParameter/deletePerid',
		        		data:param,
		       			dataType:"json",
		       			async: false,
		       			success:function callback(data){
		       				var analyMsg = data;
		       				if(analyMsg.code!="0000"){
		         				$.messager.alert('信息',analyMsg.msg,'info',function(){});
		         			}else{
		         				refreshGrid();
		        			}
		       			}
		       		});	

	        });						
       	}
		

		function btnSjdy() {
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        $.messager.alert("信息", "请先选择一个项目！", "info");
		        return;
		    }
		    var row = rows[0];
		    var url = String.format('${path}/jcxx/sbcs/toSjdy?id={0}', row.id);
		    layer.open({
				  type: 2,
				  title: '数据关系设置',
				  shadeClose: false,
				  shade: 0.3,
				  area: ['800px', '400px'],
				  content: url,
				  success: function(layero, index){
					  layer_jqobj_sjdy = layero;
					  layer_index_sjdy = index;
				  },
				  end: function () {
					  layer_jqobj_sjdy = null;
					  layer_index_sjdy = null;
				  }			  
			}); 
       	}
			
		</script>
	</head>
  <body  style="margin:0px; padding:0px;" >
  <%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" >
		<div region="center" style="padding: 5px;"  border="false">
			<div class="easyui-layout" fit="true"  border="false"> 
				<div id="divNorth" region="north" title="查询条件" border="true"
					noheader="false"
					style="padding: 5px; height: 95px; background: none repeat scroll 0 0 #EFEFEF;">
					<table>
						<tr>
							<td>纳税主体：</td>
							<td style="width: 280px">
								<select id="taxPayerId" name="taxPayerId" style="width:300px;">
									<option value="">--请选择--</option>
									<c:forEach items="${listDto }" var="list">
										<option value="${list.orgCode}">${list.orgName}</option>
									</c:forEach>
								</select>
							</td>
							<td>税（费）种：</td>							
							<td align="left">
								<select id="taxCode" name="taxCode" style="width:200px;">
									<option value="">--请选择--</option>
									<c:forEach var="item"  items="${taxClassList}">
										<option value="${item.dictCode}">${item.dictName}</option>
									</c:forEach>
								</select>									
							</td>
						</tr>
						<tr>
							<td>所属期起止：</td>
							<td colspan="2">
								<input class="easyui-datebox" id="taxperdFrom" name="taxperdFrom" data-options="editable:false" value="" style="width:145px;">-<input class="easyui-datebox" id="taxperdTo" name="taxperdTo" data-options="editable:false" value="" style="width:145px;">
							</td>													
							<td align="right"><input class="search-btn-blue" style="margin-left:10px" type="button" onclick="btnQuery();" value="查询"></td>
						</tr>
					</table>
				</div>			
				<div region="center" title="" border="false" noheader="true" style="padding: 5px 0 0 0;">
				  <table id="tt" title="" border="true"></table>
			    </div>
			</div>
	    </div>
    </div>
    <div id="tb" style="padding: 1px; height: auto; display: none;">
        <div>
        	<a id="btn_add_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="false" onclick="btnBatchAdd()">新增</a>
			<a id="btn_edit_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="false" onclick="btnEdit()">修改</a>
			<a id="btn_del_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="false" onclick="btnDel()">删除</a>
			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnSjdy()">数据关系</a>
<%-- 			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnSscs()">涉税参数</a>
			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnSjdy()">数据关系</a>
			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnYssz()">应税设置</a>
			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnSgjz()">手工结转</a>
			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnZzzdjz()">终止自动结转</a> --%>
        </div>
    </div>
</body>
</html>
